#!/bin/sh

# Copyright (C) 2009 OpenWrt.org  (C) 2010 OpenWrt.org.cn

blkdev=`dirname $DEVPATH`
if [ `basename $blkdev` != "block" ]; then

    device=`basename $DEVPATH`
    case "$ACTION" in
        add)
            mkdir -p /mnt/$device
            # ntfs-3g check
            if  [ `which fdisk` ]; then
                isntfs=`fdisk -l | grep $device | grep NTFS`
                isfuse=`lsmod | grep fuse`
                isntfs3g=`which ntfs-3g`
            else
                isntfs=""
                isvfat=""
                isfuse=""
            fi

            # mount with ntfs-3g if possible, else with default mount
            if [ "$isntfs" -a "$isfuse" -a "$isntfs3g" ]; then
                        ntfs-3g -o nls=utf8 /dev/$device /mnt/$device
            fi
            ;;
        remove)
            if [ -f /dev/${device}/swapfile ]; then
                swapoff /dev/${device}/swapfile
            fi
            umount /dev/$device
            ;;
    esac
fi